$(function() {
    //页面刷新
    $("#refresh").click(function() {
        window.location.reload();
    });

    //获取进货数据
    writeData();

    //根据条件获取进货数据
    $("#search").click(function() {
        if ($("#start").val() == "") return false;
        var stime = $("#start").val();
        var etime = $("#end").val();
        searchData(stime, etime);
    });


});

//条件获取写入列表
function searchData(stime, etime) {
    $("#table_list_2").jqGrid("setGridParam", {
        url: url + "Stock/searchLists",
        postData: {
            stime: stime,
            etime: etime
        }
    }).trigger("reloadGrid");
}

//写入列表数据
function writeData() {
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list_2").jqGrid({
        url: url + "Stock/lists",
        editurl: url + "Stock/editStock",
        datatype: "json",
        mtype: 'post',
        height: 455,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 13,
        colNames: ['序号', '种类', '日期', '供货商', '单价', '数量', '金额', '运费', '总额', '备注', '付款状态'],
        colModel: [{
            name: 'id',
            index: 'id',
            editable: true,
            width: 60,
            sorttype: "int",
            search: true
        }, {
            name: 'name',
            editable: true,
            width: 60,
        }, {
            name: 'time',
            editable: true,
            width: 90,
            formatter: "date"
        }, {
            name: 'username',
            editable: true,
            width: 100
        }, {
            name: 'price',
            editable: true,
            width: 80,
            align: "right",
        }, {
            name: 'number',
            editable: true,
            width: 80,
            align: "right",
        }, {
            name: 'total',
            editable: true,
            width: 80,
            align: "right",
        }, {
            name: 'tax',
            editable: true,
            width: 80,
            align: "right",

        }, {
            name: 'alltotal',
            editable: true,
            width: 80,
            align: "right",

        }, {
            name: 'note',
            editable: true,
            width: 100,
            sortable: false
        }, {
            name: 'is_payment',
            width: 90,
            editable: true,
            edittype: "select",
            editoptions: { value: "1:未付款;2:已付款" }
        }],
        pager: "#pager_list_2",
        viewrecords: true,
        caption: "",
        add: true,
        edit: true,
        addtext: 'Add',
        edittext: 'Edit',
        hidegrid: false
    });
    $("#table_list_2").jqGrid('navGrid', '#pager_list_2', { add: true, edit:true, del: false, search: false 
    });
}
// var fn_editSubmit=function(response,postdata){
// var json=response.responseText; 
//     json = eval("("+json+")");
//     if(json.status == "success"){
//         $("#table_list_2").jqGrid("setGridParam").trigger("reloadGrid");
//         //layer.msg(json.reson,{icon:1});
//     }else{
//         $("#table_list_2").jqGrid("setGridParam").trigger("reloadGrid");
//         //layer.msg(json.reson,{icon:2});
//     }
// }

// //重写editOptions
// var editOptions={  
// closeOnEscape: true, afterSubmit: fn_editSubmit
// }
